﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
// Based off CDC's Epi Info 7 DbDriverBase class; see http://epiinfo.codeplex.com

namespace NutriStat.Data
{
    public abstract class DbDriverBase : NutriStat.Data.IDbDriver
    {
        #region Public Events

        #endregion Public Events

        #region Public Properties
        public abstract string FullName
        {
            get;
        }

        public abstract string DbName
        {
            get;
            set;
        }

        public abstract string ConnectionString
        {
            get;
            set;
        }

        public abstract string OleConnectionString
        {
            get;
        }

        public abstract string DataSource
        {
            get;
        }

        public abstract string ConnectionDescription
        {
            get;
        }
        #endregion Public Properties

        #region Public Methods
        public abstract bool TestConnection();
        public abstract void CreateTable(string tableName, List<TableColumn> columns);
        public abstract int GetTableCount();
        public abstract DataTable Select(Query selectQuery);
        public abstract DataTable Select(Query selectQuery, DataTable table);
        public abstract bool ColumnExists(string tableName, string columnName);
        public abstract int ExecuteNonQuery(Query nonQueryStatement);
        public abstract int ExecuteNonQuery(Query nonQueryStatement, IDbTransaction transaction);
        public abstract object ExecuteScalar(Query scalarStatement);
        public abstract object ExecuteScalar(Query scalarStatement, IDbTransaction transaction);
        public abstract bool DeleteTable(string tableName);
        public abstract bool TableExists(string tableName);
        public abstract DataTable GetTableData(string tableName);
        public abstract DataTable GetTableData(string tableName, string columnNames);
        public abstract DataTable GetTableData(string tableName, string columnNames, string sortCriteria);
        public abstract IDataReader GetTableDataReader(string tableName);
        public abstract IDataReader ExecuteReader(Query selectQuery);
        public abstract List<string> GetTableColumnNames(string tableName);
        public abstract DataView GetTextColumnNames(string tableName);
        public abstract IDbTransaction OpenTransaction();
        public abstract IDbTransaction OpenTransaction(IsolationLevel isolationLevel);
        public abstract void CloseTransaction(IDbTransaction transaction);
        public abstract void Update(DataTable dataTable, string tableName, Query insertQuery, Query updateQuery);
        
        public virtual void Dispose()
        {
        }

        
        public abstract List<string> GetTableNames();
        public abstract Query CreateQuery(string ansiSqlStatement);
        #endregion Public Methods

        #region IDbDriver Members

        public abstract string IdentifyDatabase();
        public abstract string InsertInEscape(string str);

        public List<string> InsertInEscape(List<string> strings)
        {
            List<string> newList = new List<string>();
            foreach (string str in strings)
            {
                newList.Add(InsertInEscape(str));
            }
            return newList;
        }

        public virtual string FormatDate(DateTime dt)
        {            
            return "";
        }
        
        public virtual string FormatDateTime(DateTime dt)
        {            
            return "";
        }
        
        public virtual string FormatTime(DateTime dt)
        {            
            return "";
        }
        
        public abstract string GetDbSpecificColumnType(GenericDbColumnType dataType);
        #endregion
    }
}

